package main

import (
	"fmt"
)

func main() {
	msg := make(chan int, 5)
	done := make(chan bool)

	go func() {
		for {
			i, more := <-msg
			if more {
				fmt.Println("receive ,", i)
			} else {
				fmt.Println("wait msg")
				done <- true
				return
			}
		}
	}()

	for j := 0; j < 5; j++ {
		msg <- j
		fmt.Println("send one")
	}
	close(msg)
	fmt.Println("send all jobs")
	<-done
}
